#ifndef STLMODELATTRIBUTESCALCULATOR_H
#define STLMODELATTRIBUTESCALCULATOR_H

#include <QVector3D>
#include <QVector>
#include <QMatrix4x4>
#include <cmath>

#include <execution>

#include "ModelFormation.h"

class ModelAttributesCalculator
{
public:
    ///
    /// \brief calModelCentroid
    /// 计算三角面片加权质心代替整体模型的质心
    /// \return 整体模型的质心坐标
    ///
    static QVector3D calModelCentroid(const QVector<Triangle>& stl_model_meshes);
    ///
    /// \brief calModelInitPhaseNorm
    /// 使用PCA，获取模型朝向面向量
    /// \return 模型朝向向量
    ///
    static QVector3D calModelInitPhaseNorm(const QVector<Triangle>& stl_model_meshes);
};

QVector3D jobn1(
    const QVector3D& vertex,
    const QVector4D& rgba,
    const QVector3D& centroid,
    const QVector3D& planeNormal,
    float radius,
    const QVector3D& vertexNormal);

float job0(const Vertex& vertex);

std::pair<QVector<Triangle>, QVector<Edge>> job1(
    const QVector<Triangle>& triangles,
    const QVector<Edge>& edges,
    const QVector3D& centroid,
    const QVector3D& planeNormal,
    float radius);

void job2(
    QVector<QVector<QVector<Vertex>>>& contours,
    const QVector3D& centroid,
    const QVector3D& planeNormal,
    float radius);

// job3：利用job2产出的所有收缩后点云，沿plane_norm方向全量结构化切片（不丢点、不等间距）
// 核心：按点沿plane_norm的投影值（dot值）分组，每个分组为一个切片，包含所有对应点
void job3(QVector<QVector<QVector<Vertex>>> &contours,  // 输入：job2收缩后的全量点云（输出：结构化切片）
          const QVector3D &plane_norm,
          QVector<float>& out_slices_intervals,
          const QVector3D& u_axis, const QVector3D& v_axis,
          float dot_merge_threshold = 1e-6f);

#endif
